package api

import (
	"gateway/basic/config"
	__ "gateway/basic/proto"
	"gateway/handler/request"
	"github.com/gin-gonic/gin"
	"net/http"
)

func VideoList(c *gin.Context) {
	var param request.VideoList
	if err := c.ShouldBind(&param); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"mes":  "参数错误",
		})
	}
	r, err := config.Usercline.VideoList(c, &__.VideoListReq{
		Page:     param.Page,
		PageSize: param.PageSize,
		Status:   param.Status,
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"mes":  err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"mes":  "展示成功",
		"data": r,
	})

}

func VideoDetail(c *gin.Context) {
	var param request.VideoDetail
	if err := c.ShouldBind(&param); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"mes":  "参数错误",
		})
	}
	r, err := config.Usercline.VideoDetail(c, &__.VideoDetailReq{
		Id: param.Id,
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"mes":  err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"mes":  "视频详情成功",
		"data": r,
	})
}

func CollectVideo(c *gin.Context) {
	var param request.CollectVideo
	if err := c.ShouldBind(&param); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"mes":  "参数错误",
		})
	}
	r, err := config.Usercline.CollectVideo(c, &__.CollectVideoReq{
		UserId:  param.UserId,
		VideoId: param.VideoId,
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"mes":  err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"mes":  "收藏视频成功",
		"data": r.CollectId,
	})
}
